package com.grablist.feihu.grablist.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.grablist.feihu.grablist.R;
import com.grablist.feihu.grablist.base.BaseAppAdapter;
import com.grablist.feihu.grablist.event.RemoveInfoEvent;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by chenjian
 */
public class WirelessAdp extends BaseAppAdapter {
    private Context mContext;
    private List<String> mData;


    public WirelessAdp(Context context) {
        super(context);
        mContext = context;
        mData = new ArrayList<String>();
    }


    public void setData(List<String> data) {
        if (data != null) {
            mData = data;
        }
    }

    public List<String> getData() {
        return mData;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        final Holder holder;
        if (convertView == null) {
            holder = new Holder();
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.item_select_info, null);
            holder.name = (TextView) convertView.findViewById(R.id.select_info_daikun_text);
            holder.clear = (TextView) convertView.findViewById(R.id.select_info_one_clear);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        holder.name.setText(mData.get(position));
        holder.clear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(new RemoveInfoEvent(position));

            }
        });

        return convertView;
    }

    class Holder {
        TextView name;
        TextView clear;
    }


}
